<%@ page import="com.malethan.seemorej.SeemoreJ" %>
<%@ page import="com.malethan.seemorej.Flash" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<#assign pojoNameLower = util.getLowerCaseFirstLetter(pojo.shortName)>
<#assign pojoNamePlural = util.getPluralForWord(pojoNameLower)>

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="sj" uri="http://java.malethan.com/seemorej/taglib/seemorej.tld" %>

<c:set var="timestampPattern" value="EEE, d MMM yyyy HH:mm:ss z" />
<c:set var="datePattern" value="EEE, d MMM yyyy" />
<c:set var="timePattern" value="HH:mm:ss" />

<html>
<head>
    <title>Listing all ${util.humaniseCamelCase(pojoNamePlural)}</title>
</head>
<body>

<c:set var="success"><%=SeemoreJ.flash(Flash.SUCCESS)%></c:set>
<c:if test="${'$'}{!empty(success) && success != 'null'}">
    <div class="success">
        <p><c:out value="${'$'}{success}" /></p>
    </div>
</c:if>

<c:set var="notice"><%=SeemoreJ.flash(Flash.NOTICE)%></c:set>
<c:if test="${'$'}{!empty(notice) && notice != 'null'}">
    <div class="notice">
        <p><c:out value="${'$'}{notice}" /></p>
    </div>
</c:if>

<c:set var="error"><%=SeemoreJ.flash(Flash.ERROR)%></c:set>
<c:if test="${'$'}{!empty(error) && error != 'null'}">
    <div class="error">
        <p><c:out value="${'$'}{error}" /></p>
    </div>
</c:if>

<table>

<tr>
<#foreach field in pojo.getAllPropertiesIterator()>
    <#if !c2h.isCollection(field) && !c2h.isManyToOne(field) && !c2j.isComponent(field)>
        <#lt/>    <th>${util.humaniseCamelCase(field.name)} </th>
    </#if>
</#foreach>
</tr>

<c:forEach items="${'$'}{${pojoNamePlural}}" var="${pojoNameLower}">
<tr>
    <#foreach field in pojo.getAllPropertiesIterator()>
    <#if field.equals(pojo.identifierProperty)>
        <td>
             <#lt/>    <c:set var="showUrl">
             <#lt/>    <%-- TODO: use something more concise to generate URLs --%>
             <#lt/>      <c:url value="/seemore">
             <#lt/>        <c:param name="_sjController" value="${'$'}{param._sjController}" />
             <#lt/>        <c:param name="_sjAction" value="show" />
             <#lt/>        <c:param name="id" value="${'$'}{${pojoNameLower}.${field.name}}" />
             <#lt/>        <c:param name="_sjFormat" value="html" />
             <#lt/>      </c:url>
             <#lt/>    </c:set>
             <#lt/>    <a href="${'$'}{showUrl}"><c:out value="${'$'}{${pojoNameLower}.${field.name}}" /></a>
        </td>
    <#elseif !c2h.isCollection(field) && !c2h.isManyToOne(field) && !c2j.isComponent(field)>
        <td>
            <#if field.value.typeName == "date" || field.value.typeName == "time" || field.value.typeName == "timestamp">
            <#lt/>        <fmt:formatDate value="${'$'}{${pojoNameLower}.${field.name}}" pattern="${'$'}{${field.value.typeName}Pattern}"/>
            <#elseif field.value.typeName == "boolean" || field.value.typeName == "java.lang.Boolean">
                <#lt/>    <input type="checkbox" disabled="disabled" <c:if test="${'$'}{${pojoNameLower}.${field.name}}">checked="checked"</c:if>/>
            <#else>
                <#lt/>    <c:out value="${'$'}{${pojoNameLower}.${field.name}}" />
            </#if>
        </td>
    </#if>
    </#foreach>
</tr>
</c:forEach>
</table>

<%-- TODO: use something more concise to generate URLs --%>
<c:set var="newUrl">
  <c:url value="/seemore">
    <c:param name="_sjController" value="${'$'}{param._sjController}" />
    <c:param name="_sjAction" value="new" />
    <c:param name="_sjFormat" value="html" />
  </c:url>
</c:set>
<p>
    <a href="${'$'}{newUrl}">New ${pojoNameLower}</a>
</p>
</body>
</html>